#include "debug.h"
#include "Lock.h"

#ifdef _DEBUG


static CriticalSection dbgCS;

void dbgprint(const char *format, ...)
{
    static DWORD pid=0;
    va_list vl;
    char dbgbuf1[2048], dbgbuf2[2048];

    // Prepend the process ID to the message
    if ( 0 == pid ) {
        pid = GetCurrentProcessId();
    }

    Lock lock(dbgCS);

    va_start(vl, format);
    wvsprintf(dbgbuf1, format, vl);
    wsprintf(dbgbuf2, "%lu: %s\r\n", pid, dbgbuf1);
    va_end(vl);

    OutputDebugString(dbgbuf2);
}


#endif //_DEBUG
